// import 'dart:collection';

// import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_community/utils/http.dart';

class HouseItem extends StatefulWidget {
  const HouseItem({super.key, required this.houseInfo});
  final houseInfo;

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  Map _houseListData = {};
  @override
  void initState() {
    super.initState();
    setState(() {
      // 获取数据
      _houseListData = widget.houseInfo;
    });
  }

  //右侧审核状态
  Widget _buildTagItem(int status) {
    List tag = [
      {
        "name": "审核中",
        'bgcolor': const Color.fromARGB(255, 162, 208, 246),
        "textcolor": const Color.fromARGB(255, 171, 244, 249)
      },
      {
        "name": "审核通过",
        'bgcolor': const Color.fromARGB(255, 31, 184, 59),
        "textcolor": const Color.fromARGB(255, 123, 239, 173)
      },
      {
        "name": "审核失败",
        'bgcolor': const Color.fromARGB(255, 242, 81, 81),
        "textcolor": const Color.fromARGB(255, 246, 149, 164)
      },
    ];
    return Container(
      width: 65,
      padding: const EdgeInsets.all(1),
      decoration: BoxDecoration(
        color: tag[status]['bgcolor'],
        borderRadius: BorderRadius.circular(5),
      ),
      //审核状态
      child: Text(
        tag[status]['name'],
        style: TextStyle(color: tag[status]['textcolor']),
        textAlign: TextAlign.center,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, '/house_detail',
            arguments: _houseListData);
      },
      child: Container(
        // height: 100,
        padding: const EdgeInsets.all(12),
        margin: const EdgeInsets.all(10),
        color: Colors.white,
        child: Column(
          children: [
            //房屋名称
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  _houseListData['point'],
                  style: const TextStyle(
                      fontSize: 18, fontWeight: FontWeight.bold),
                ),
                //审核状态
                _buildTagItem(_houseListData['status'] - 1)
              ],
            ),
            const SizedBox(height: 10),
            //房间号
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const Text(
                  '房间号',
                  style: TextStyle(color: Colors.grey),
                ),
                Text('${_houseListData['building']}${_houseListData['room']}')
              ],
            ),
            const SizedBox(height: 10),
            //联系人
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const Text(
                  '业主',
                  style: TextStyle(color: Colors.grey),
                ),
                Text(_houseListData['name'])
              ],
            ),
          ],
        ),
      ),
    );
  }
}
